﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using MsTestUtilities.SolutionAnalysis;
using System.Linq;
using System.Xml.Linq;

namespace SolutionAnalysisTests.Testing.ItemTests
{
    [TestClass]
    public class ItemWithProperties
    {
        private string _itemGroupXml = @"<ProjectReference Include=""..\SolutionAnalysis\SolutionAnalysis.csproj"">
      <Project>{fa6a07cc-57d2-412b-9c1b-173b84a7a84d}</Project>
      <Name>SolutionAnalysis</Name>
    </ProjectReference>";

        private Item _item;

        [TestInitialize]
        public void Setup()
        {
            var xml = XElement.Parse(_itemGroupXml);
            _item = new Item(xml);
        }


        [TestMethod]
        public void FetchItemName()
        {
            Assert.AreEqual("ProjectReference", _item.Name);
        }

        [TestMethod]
        public void IncludeAttribute()
        {
            Assert.AreEqual(@"..\SolutionAnalysis\SolutionAnalysis.csproj", _item.Include);
        }

        [TestMethod]
        public void PropertyCount()
        {
            Assert.AreEqual(2, _item.Properties.Count());
        }

        [TestMethod]
        public void ProjectPropertyKey()
        {
            Assert.IsTrue(_item.Properties.ContainsKey("Project"));
        }

        [TestMethod]
        public void NamePropertyKey()
        {
            Assert.IsTrue(_item.Properties.ContainsKey("Name"));
        }

        [TestMethod]
        public void ProjectPropertyValue()
        {
            Assert.AreEqual("{fa6a07cc-57d2-412b-9c1b-173b84a7a84d}", _item.Properties["Project"]);            
        }

        [TestMethod]
        public void NamePropertyValue()
        {
            Assert.AreEqual("SolutionAnalysis", _item.Properties["Name"]);                        
        }
    }
}
